﻿/**
 * FFXIIRCGateway
 *
 * @package ffxiircgateway
 * @version $Id: ConsoleForm.cs 15 2009-03-17 03:33:30Z ayunyan $
 * @author ayunyan <ayu@commun.jp>
 * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License 2.0
 * @link http://code.google.com/p/ffxiircgateway
 */
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FFXIIRCGateway
{
    public partial class ConsoleForm : Form
    {
        private IRCClient ircClient;

        public ConsoleForm(IRCClient ircClient)
        {
            this.ircClient = ircClient;
            InitializeComponent();
            CreateGraphics(); // コントロールのハンドル作成前はInvokeRequiredが常にfalseになってしまう
        }

        private void ConsoleForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                e.Cancel = true;
                this.Hide();
            }
        }

        private delegate void addLogDelegate(string message);
        public void addLog(string message)
        {
            if (this.InvokeRequired)
            {
                this.Invoke(new addLogDelegate(addLog), new object[] { message });
                return;
            }
            this.textLog.AppendText(DateTime.Now.ToString("[HH:mm] ") + message + "\r\n");
        }

        private void textInput_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (this.textInput.Text.Length > 1 && this.textInput.Text.Substring(0, 1) == "/")
                {
                    this.ircClient.Send(this.textInput.Text.Substring(1));
                }
                this.textInput.Text = "";
            }
        }
    }
}
